import { defineComponent, onMounted, computed } from 'vue'
import Draw from './draw'
import { useWebSocketStore } from '@/store/websocket'
import {useStore} from "vuex"; // 导入全局WebSocket store

export default defineComponent({
  components: {
    Draw
  },
  setup() {
    const store = useStore()
    const strategy = computed(() => store.getters.currentStrategy) // 策略列表
    const wsStore = useWebSocketStore()

    // 直接从store中获取响应式数据
    const cdata = computed(() => ({
      hours: wsStore.cdata[strategy.value].hours,
      electricityCost: wsStore.cdata[strategy.value].electricityCost,
      powerConsumption: wsStore.cdata[strategy.value].powerConsumption,
      unitPrice: wsStore.cdata[strategy.value].unitPrice,
      actualLoad: wsStore.cdata.actualLoad,
    }))
    console.log(cdata.value,'bottomLeft')

    // // 生命周期
    // onMounted(() => {
    // })

    return () => {
      return <div>
        <Draw cdata={cdata.value} />
      </div>
    }
  }
})